package com.ljc.config;

import com.ljc.im.handler.MsgHandlerFactory;
import com.ljc.im.server.ImServerStart;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @Author: ljc
 * @Date:Created in 9:05 2022/2/25
 */
@Slf4j
@Configuration
public class ImServerConfig {
    @Value("${im.server.port}")
    private int imPort;

    @Bean
    ImServerStart imServerStart() {
        try {
            //启动tio服务
            ImServerStart imServerStart = new ImServerStart(imPort);
            imServerStart.start();
            //处理消息处理类别
            MsgHandlerFactory.init();

            return imServerStart;
        }
        catch (IOException e) {
            log.error("server启动失败" ,e);
        }
        return null;
    }

}
